package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.Issue;
import com.cskaoyan.bean.ListData;
import com.cskaoyan.service.IssueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RequestMapping("admin/issue")
@RestController
public class IssueController {

    @Autowired
    IssueService issueService;

    @GetMapping("list")
    public BaseRespVo list(Integer page,
                           Integer limit,
                           String question,
                           String sort,
                           String order) {

        ListData<Issue> issueList = issueService.queryList(page, limit, question, sort, order);
        return BaseRespVo.ok(issueList);
    }

    @PostMapping("create")
    public BaseRespVo create(@RequestBody Issue issue) {
        Issue issueResult = issueService.create(issue);
        return BaseRespVo.ok(issueResult);
    }

    @PostMapping("delete")
    public BaseRespVo delete(@RequestBody Issue issue) {
        int delete = issueService.delete(issue);
        if (delete != 1) {
            return BaseRespVo.fail("删除失败");
        }
        return BaseRespVo.ok();
    }

    @PostMapping("update")
    public BaseRespVo update(@RequestBody Issue issue) {
        int update = issueService.update(issue);
        if (update == 0) {
            return BaseRespVo.ok("编辑失败");
        }

        return BaseRespVo.ok(issue);
    }


}
